import {defineStore} from "pinia"
import {getToday,getTomorrow,diffDay} from "@/utils/getDate"
import newaxios from "@/service/request"
let page=1
const useHomeStore = defineStore("home",{
    state: () => ({
        startDate:getToday(),
        leaveDate:getTomorrow(),
        hotCategories:[],
        hotRoom:[]
    }),
    getters:{
        during: (state) => diffDay(state.startDate,state.leaveDate)
    },
    actions:{
        changDate(datas){
            this.startDate = datas[0]
            this.leaveDate = datas[1]
        },
        async getHotCategories(){
            const res = await newaxios.get("/home/categories")
            this.hotCategories = res.data
        },
        
        async getHotRoom(){
            const res = await newaxios.get("/home/houselist",{
                params:{
                    page
                }
            })
            page++
            this.hotRoom.push(...res.data)
        }
    }
})

export default useHomeStore